package com.zeta.eduservice.controller.question;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.EduClasss;
import com.zeta.eduservice.entity.question.EduCourse;
import com.zeta.eduservice.entity.question.EduCourseClass;
import com.zeta.eduservice.service.EduCourseClassService;

/**
 * <p>
 * 课程 班级中间表 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2021-03-29
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_course_class")
public class EduCourseClassController {

	@Autowired
	private EduCourseClassService courseClassService;
	
	@GetMapping("getListByCourseId/{courseId}/{current}/{limit}")
	public R getClassListByCourseId(@PathVariable String courseId,@PathVariable long current, @PathVariable long limit) {
		Page<EduClasss> page=new Page<>(current,limit);
		List<EduClasss> classListByCourseId = courseClassService.getClassListByCourseId(page,courseId);
		long total = page.getTotal();
		return R.ok().data("total", total).data("rows", classListByCourseId);
	}
	@GetMapping("getListByClassId/{classId}")
	public R getCourseListByClassId(@PathVariable String classId,@PathVariable long current, @PathVariable long limit) {
		Page<EduCourse> page=new Page<>(current,limit);
		List<EduCourse> courseListByClassId = courseClassService.getCourseListByClassId(page,classId);
			long total = page.getTotal();
		return R.ok().data("total", total).data("rows", courseListByClassId);
	}
	@PostMapping("")
	public R save(@RequestBody EduCourseClass courseClass) {
		courseClassService.save(courseClass);
		return R.ok();
	}
}

